from re import template
from flask import jsonify, render_template
from flask_mail import Message
from App.ext import mail


def Login_State(a):
    if a == 208:
        return jsonify({"code": 208, "msg": "请输入用户名"})
    if a == 203:
        return jsonify({"code": 203, "msg": "用户名未注册，请重新注册"})
    if a == 205:
        return jsonify({"code": 205, "msg": "密码错误，请重新输入！"})
    if a == 207:
        return jsonify({"code": 207, "msg": "密码正确，登录成功！"})



def Register_State(a):
    if a == 201:
        return jsonify({"code": 201, "msg": "邮箱/密码，请检查！"})
    if a == 203:
        return jsonify({"code": 203, "msg": "密码必须是大小写字母+数字，请检查！"})
    if a == 207:
        return jsonify({"code": 207, "msg": "恭喜，注册成功！"})
    if a == 208:
        return jsonify({"code": 208, "msg": "验证码错误，请重新输入"})
    # if a == 202:
    #     return jsonify({"code": 202, "msg": "用户名必须是大小写字母+数字，请检查！"})




class Mail():
    def __init__(self,recipients,code):
        self.recipients=recipients
        self.code = code
    def SendMail(self):
        msg = Message("欢迎使用网络攻防实训平台",recipients=[self.recipients])
        msg.body = "body"
        msg.html = render_template ('email.html',code=self.code)
        mail.send(message=msg)
        
        
        
        
        
        
        
        
def Top(j):
    a =  j.code
    return a

def select_code(T):
    b = []
    for i in T:
        b.append(Top(i))
    return b